home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
mint
/
mint104s.zoo
/
mint.src
/
dos.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-08
|
13KB
|
583 lines
/*
Copyright 1990,1991,1992 Eric R. Smith.
Copyright 1992 Atari Corporation.
All rights reserved.
*/
/* miscellaneous DOS functions, and the DOS initialization function */
#include "mint.h"
#define DOS_MAX 0x140
Func dos_tab[DOS_MAX];
short dos_max = DOS_MAX;
static void alarmme P_((PROC *));
long ARGS_ON_STACK
s_version()
{
return Sversion();
}
/*
* Super(new_ssp): change to supervisor mode.
*/
long ARGS_ON_STACK
s_uper(new_ssp)
long new_ssp;
{
int in_super;
long r;
TRACE(("Super"));
in_super = curproc->ctxt[SYSCALL].sr & 0x2000;
if (new_ssp == 1) {
r = in_super ? -1L : 0;
}
else {
curproc->ctxt[SYSCALL].sr ^= 0x2000;
r = curproc->ctxt[SYSCALL].ssp;
if (in_super) {
if (new_ssp == 0) {
DEBUG(("bad Super call"));
raise(SIGSYS);
}
else {
curproc->ctxt[SYSCALL].usp =
curproc->ctxt[SYSCALL].ssp;
curproc->ctxt[SYSCALL].ssp = new_ssp;
}
}
else {
curproc->ctxt[SYSCALL].ssp =
new_ssp ? new_ssp : curproc->ctxt[SYSCALL].usp;
}
}
return r;
}
/*
* get/set time and date functions
*/
long ARGS_ON_STACK t_getdate() { return datestamp; }
long ARGS_ON_STACK t_gettime() { return timestamp; }
long ARGS_ON_STACK t_setdate(date)
int date;
{
long r = Tsetdate(date);
datestamp = Tgetdate();
return r;
}
long ARGS_ON_STACK t_settime(time)
int time;
{
long r = Tsettime(time);
timestamp = Tgettime();
return r;
}
/*
* GEMDOS extension: Syield(): give up the processor if any other
* processes are waiting. Always returns 0.
*/
long ARGS_ON_STACK
s_yield()
{
/* reward the nice process */
curproc->curpri = curproc->pri;
sleep(READY_Q, curproc->wait_cond);
return 0;
}
/*
* GEMDOS extension:
* Prenice(pid, delta) sets the process priority level for process pid.
* A "nice" value < 0 increases priority, one > 0 decreases it.
* Always returns the new priority (so Prenice(pid, 0) queries the current
* priority).
*
* NOTE: for backward compatibility, Pnice(delta) is provided and is equivalent
* to Prenice(Pgetpid(), delta)
*/
long ARGS_ON_STACK
p_renice(pid, delta)
int pid, delta;
{
PROC *p;
if (pid <= 0 || 0 == (p = pid2proc(pid))) {
return EFILNF;
}
if (curproc->euid && curproc->euid != p->ruid
&& curproc->ruid != p->ruid) {
DEBUG(("Prenice: process ownership error"));
return EACCDN;
}
p->pri -= delta;
if (p->pri < MIN_NICE) p->pri = MIN_NICE;
if (p->pri > MAX_NICE) p->pri = MAX_NICE;
p->curpri = p->pri;
return ((long)p->pri) & 0x0ffff;
}
long ARGS_ON_STACK
p_nice(delta)
int delta;
{
return p_renice(curproc->pid,delta);
}
/*
* GEMDOS extensions: routines for getting/setting process i.d.'s and
* user i.d.'s
*/
long ARGS_ON_STACK p_getpid() { return curproc->pid; }
long ARGS_ON_STACK p_getppid() { return curproc->ppid; }
long ARGS_ON_STACK p_getpgrp() { return curproc->pgrp; }
/* note: Psetpgrp(0, ...) is equivalent to Psetpgrp(Pgetpid(), ...) */
/* also note: Psetpgrp(x, 0) is equivalent to Psetpgrp(x, x) */
long ARGS_ON_STACK p_setpgrp(pid, newgrp)
int pid, newgrp;
{
PROC *p;
if (pid == 0)
p = curproc;
else if (0 == (p = pid2proc(pid)))
return EFILNF;
if ( (curproc->euid) && (p->ruid != curproc->ruid)
&& (p->ppid != curproc->pid) )
return EACCDN;
if (newgrp < 0)
return p->pgrp;
if (newgrp == 0)
newgrp = p->pid;
return (p->pgrp = newgrp);
}
long ARGS_ON_STACK p_getuid() { return curproc->ruid; }
long ARGS_ON_STACK p_getgid() { return curproc->rgid; }
long ARGS_ON_STACK p_geteuid() { return curproc->euid; }
long ARGS_ON_STACK p_getegid() { return curproc->egid; }
long ARGS_ON_STACK
p_setuid(id)
int id;
{
if (curproc->euid == 0 || curproc->ruid == id) {
curproc->ruid = curproc->euid = id;
return id;
}
return EACCDN;
}
long ARGS_ON_STACK
p_setgid(id)
int id;
{
if (curproc->euid == 0 || curproc->egid == 0 || curproc->rgid == id) {
curproc->egid = curproc->rgid = id;
return id;
}
return EACCDN;
}
/*
* a way to get/set process-specific user information. the user information
* longword is set to "arg", unless arg is -1. In any case, the old
* value of the longword is returned.
*/
long ARGS_ON_STACK
p_usrval(arg)
long arg;
{
long r;
TRACE(("Pusrval"));
r = curproc->usrdata;
if (arg != -1L)
curproc->usrdata = arg;
return r;
}
/*
* set the file creation mask to "mode". Returns the old value of the
* mask.
*/
long ARGS_ON_STACK p_umask(mode)
unsigned mode;
{
long oldmask = curproc->umask;
curproc->umask = mode & (~S_IFMT);
return oldmask;
}
/*
* get/set the domain of a process. domain 0 is the default (TOS) domain.
* domain 1 is the MiNT domain. for now, domain affects read/write system
* calls and filename translation.
*/
long ARGS_ON_STACK
p_domain(arg)
int arg;
{
long r;
TRACE(("Pdomain(%d)", arg));
r = curproc->domain;
if (arg >= 0)
curproc->domain = arg;
return r;
}
/*
* get process resource usage. 8 longwords are returned, as follows:
* r[0] == system time used by process
* r[1] == user time used by process
* r[2] == system time used by process' children
* r[3] == user time used by process' children
* r[4] == memory used by process
* r[5] - r[7]: reserved for future use
*/
long ARGS_ON_STACK
p_rusage(r)
long *r;
{
r[0] = curproc->systime;
r[1] = curproc->usrtime;
r[2] = curproc->chldstime;
r[3] = curproc->chldutime;
r[4] = memused(curproc);
return 0;
}
/*
* get/set resource limits i to value v. The old limit is always returned;
* if v == -1, the limit is unchanged, otherwise it is set to v. Possible
* values for i are:
* 1: max. cpu time (milliseconds)
* 2: max. core memory allowed
* 3: max. amount of malloc'd memory allowed
*/
long ARGS_ON_STACK
p_setlimit(i, v)
int i;
long v;
{
long oldlimit;
switch(i) {
case 1:
oldlimit = curproc->maxcpu;
if (v >= 0) curproc->maxcpu = v;
break;
case 2:
oldlimit = curproc->maxcore;
if (v >= 0) {
curproc->maxcore = v;
recalc_maxmem(curproc);
}
break;
case 3:
oldlimit = curproc->maxdata;
if (v >= 0) {
curproc->maxdata = v;
recalc_maxmem(curproc);
}
break;
default:
DEBUG(("Psetlimit: invalid mode %d", i));
return EINVFN;
}
TRACE(("p_setlimit(%d, %ld): oldlimit = %ld", i, v, oldlimit));
return oldlimit;
}
/*
* pause: just sleeps on IO_Q, with wait_cond == -1. only a signal will
* wake us up
*/
long ARGS_ON_STACK
p_pause()
{
TRACE(("Pause"));
sleep(IO_Q, -1L);
return 0;
}
/*
* helper function for t_alarm: this will be called when the timer goes
* off, and raises SIGALRM
*/
static void
alarmme(p)
PROC *p;
{
p->alarmtim = 0;
post_sig(p, SIGALRM);
}
/*
* t_alarm(x): set the alarm clock to go off in "x" seconds. returns the
* old value of the alarm clock
*/
long ARGS_ON_STACK
t_alarm(x)
long x;
{
long oldalarm;
TIMEOUT *t;
/* see how many milliseconds there were to the alarm timeout */
oldalarm = 0;
if (curproc->alarmtim) {
for (t = tlist; t; t = t->next) {
oldalarm += t->when;
if (t == curproc->alarmtim)
goto foundalarm;
}
DEBUG(("Talarm: old alarm not found!"));
oldalarm = 0;
curproc->alarmtim = 0;
foundalarm:
;
}
oldalarm = (oldalarm+999) / 1000; /* convert to seconds */
/* we were just querying the alarm */
if (x < 0)
return oldalarm;
/* cancel old alarm */
if (curproc->alarmtim)
canceltimeout(curproc->alarmtim);
/* add a new alarm, to occur in 1000*x milliseconds */
if (x)
curproc->alarmtim = addtimeout(1000*x, alarmme);
else
curproc->alarmtim = 0;
return oldalarm;
}
/*
* sysconf(which): returns information about system configuration.
* "which" specifies which aspect of the system configuration is to
* be returned:
* -1 max. value of "which" allowed
* 0 max. number of memory regions per proc
* 1 max. length of Pexec() execution string {ARG_MA